import requests

def get_weather(city):
    """
    获取指定城市的天气
    """
    url = f"http://wttr.in/{city}?format=j1"
    try:
        reponse = requests.get(url)
        data = reponse.json()
        if "current_condition" in data:
            temp = data["current_condition"][0]["temp_C"]
            weahther = data["current_condition"][0]["weatherDesc"][0]["value"]
            return f"{city}当前的温度：{temp}℃，天气为：{weahther}"
    except Exception as e:
        return f"天气查询失败：{str(e)}"

if __name__=="__main__":
    city = "杭州"
    print(get_weather(city=city))
